package net.wofly.common.validator;

import net.wofly.common.util.FileTypeAddress;
import org.springframework.web.multipart.MultipartFile;

/**
 *
 * @author siqingwei
 * @date 2018/3/11
 */
public class UploadValidator {
    /**
     * 换行符
     */
    private static String lineSeparator = System.getProperty("line.separator");

    public static String validateUploadSingleFileParams(Integer fileType, MultipartFile file) {
        StringBuffer stringBuffer = new StringBuffer();
        if (!FileTypeAddress.isValueCorrect(fileType)){
            stringBuffer.append("文件类型不正确！").append(lineSeparator);
        }

        if (file == null) {
            stringBuffer.append("文件不能为空！").append(lineSeparator);
        }
        return stringBuffer.toString();
    }

    public static String validateUploadBatchFilesParams(Integer fileType, MultipartFile[] files) {
        StringBuffer stringBuffer = new StringBuffer();
        if (!FileTypeAddress.isValueCorrect(fileType)){
            stringBuffer.append("文件类型不正确！").append(lineSeparator);
        }

        if (files == null) {
            stringBuffer.append("文件不能为空！").append(lineSeparator);
        }
        return stringBuffer.toString();
    }

    public static String validateUploadSingleFileForBase64Params(Integer fileType, String fileBase64) {
        StringBuffer stringBuffer = new StringBuffer();
        if (!FileTypeAddress.isValueCorrect(fileType)){
            stringBuffer.append("文件类型不正确！").append(lineSeparator);
        }

        if (fileBase64 == null) {
            stringBuffer.append("文件不能为空！").append(lineSeparator);
        }
        return stringBuffer.toString();
    }
}
